package com.alibaba.middleware.hsf.guide.io.listener;

import com.taobao.hsf.annotation.Order;
import com.taobao.hsf.annotation.Scope;
import com.taobao.hsf.annotation.Tag;
import com.taobao.hsf.io.RequestPacket;
import com.taobao.hsf.io.ResponsePacket;
import com.taobao.hsf.io.client.Client;
import com.taobao.hsf.io.stream.ClientStream;
import com.taobao.hsf.io.stream.support.ClientStreamMessageListenerAdapter;

/**
 * @author weipeng2k 2018年03月02日 下午13:58:35
 */
@Tag({"tcp", "http"})
@Scope(Scope.Option.SINGLETON)
@Order(10000)
public class TestClientStreamMessageListener extends ClientStreamMessageListenerAdapter {

    @Override
    public void write(Client client, ClientStream stream, RequestPacket message) {
        System.out.println("client@" + client
                + " write message " + message + " to " + stream.getRemoteAddress());
    }

    @Override
    public void writeSuccess(Client client, ClientStream stream, RequestPacket message) {
        System.out.println("client@" + client
                + " write message " + message + " to " + stream.getRemoteAddress() + " success");
    }

    @Override
    public void writeFailed(Client client, ClientStream stream, RequestPacket message, Throwable cause) {
        System.out.println("client@" + client
                + " failed write message " + message + " to " + stream.getRemoteAddress());
    }

    @Override
    public void received(Client client, ClientStream stream, ResponsePacket message) {
        System.out.println("client@" + client
                + " received message " + message + " from " + stream.getRemoteAddress());
    }
}
